import type { University } from '@/types/members'
import { getUniversityByNameAPI } from '@/services/member'
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { useMemberStore } from './member'

export const useUniversityStore = defineStore('university', () => {
  const university = ref<University[]>([])
  const getUniversityByName = async (name: string) => {
    const userInfo = useMemberStore().profile
    // 如果用户信息存在，则获取用户认证信息
    if (userInfo) {
      const res = await getUniversityByNameAPI(name)
      university.value = res.data
    }
  }
  // 清理结果
  const clearUniversity = () => {
    university.value = []
  }
  return {
    university,
    getUniversityByName,
    clearUniversity,
  }
})
